package parser.prestige;

import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

/**
 * Created with IntelliJ IDEA.
 * User: msi
 * Date: 02.12.13
 * Time: 20:48
 * To change this template use File | Settings | File Templates.
 */
public abstract class AbstractNode {
    protected void addNode(XMLEventWriter eventWriter, String nodeName, String nodeValue, int tabCount) throws XMLStreamException{
        XMLEventFactory eventFactory = XMLEventFactory.newInstance();
        XMLEvent endLineEvent = eventFactory.createDTD("\n");

        //dodanie wciec
        addTabs(eventWriter, tabCount);

        eventWriter.add(eventFactory.createStartElement("","",nodeName));
        eventWriter.add(eventFactory.createCharacters(nodeValue));
        eventWriter.add(eventFactory.createEndElement("","",nodeName));
        eventWriter.add(endLineEvent);
    }

    protected void addTabs(XMLEventWriter eventWriter, int tabCount) throws XMLStreamException{
        XMLEventFactory eventFactory = XMLEventFactory.newInstance();
        XMLEvent tabulatorEvent = eventFactory.createDTD("\t");
        for (int i = 0; i < tabCount; i++) {
            eventWriter.add(tabulatorEvent);
        }
    }
}
